package com.xoa.controller.hr;

import com.xoa.model.hr.HrStaffReinstatement;
import com.xoa.model.hr.HrStaffReinstatementWithBLOBs;
import com.xoa.service.hr.HrStaffReinstatementService;
import com.xoa.util.CookiesUtil;
import com.xoa.util.ExcelUtil;
import com.xoa.util.ToJson;
import com.xoa.util.common.log.FileUtils;
import com.xoa.util.common.session.SessionUtils;
import com.xoa.util.dataSource.ContextHolder;
import org.apache.poi.hssf.usermodel.HSSFWorkbook;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.multipart.MultipartFile;

import javax.servlet.http.Cookie;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import java.io.OutputStream;

@Controller
@RequestMapping("/hr/manage")
public class HrStaffReinstatementController {

    @Autowired
    private HrStaffReinstatementService hrStaffReinstatementService;
    //主页面
    @RequestMapping("/staff_reinstatement") //   /hr/manage/staff_transfer
    public String reinstatement(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabBar";
    }

    //详情页
    @RequestMapping("/hrRehabDetail")  //     /hr/manage/tansferDetail
    public String hrRehabDetail(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabDetail";
    }

    //导入页
    @RequestMapping("/rehabExport")   //    /hr/manage/tansferExport
    public String rehabExport(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabImport";
    }

    //管理页面
    @RequestMapping("/rehabManage")   //    /hr/manage/tansferManage
    public String rehabManage(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabManager";
    }

    //新建页面
    @RequestMapping("/rehabNewedit")   //    /hr/manage//tansferNewedit
    public String rehabNewedit(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabNew";
    }

    //查询页面
    @RequestMapping("/rehabQuery")   //     /hr/manage//tansferQuery
    public String rehabQuery(HttpServletRequest request) {
        Cookie redisSessionCookie = CookiesUtil.getCookieByName(request, "redisSessionId");
        String loginDateSouse = SessionUtils.getSessionInfo(request.getSession(), "loginDateSouse", String.class, redisSessionCookie);
        ContextHolder.setConsumerType("xoa" + loginDateSouse);
        return "app/hr/hrRehab/HrRehabQuery";
    }

    /**
     * 添加
     * 郭心雨
     * 2018.07.19
     * @param hrStaffReinstatement
     * @return
     */
    @RequestMapping("/addRehab")
    @ResponseBody
    private ToJson addRehab(HttpServletRequest request,HrStaffReinstatementWithBLOBs hrStaffReinstatement){
        return hrStaffReinstatementService.addRehab(request,hrStaffReinstatement);
    }

    /**
     * 删除
     * 郭心雨
     * 2018.07.19
     * @param reinstatementId
     * @return
     */
    @RequestMapping("/delRehab")
    @ResponseBody
    private ToJson delRehab(Integer[] reinstatementId){
        return hrStaffReinstatementService.delRehab(reinstatementId);
    }

    /**
     * 修改
     * 郭心雨
     * 2018.07.19
     * @param hrStaffReinstatement
     * @return
     */
    @RequestMapping("/modifyRehab")
    @ResponseBody
    private ToJson modifyRehab(HrStaffReinstatementWithBLOBs hrStaffReinstatement){
        return hrStaffReinstatementService.modifyRehab(hrStaffReinstatement);
    }

    /**
     * 根据id查看详情
     * 郭心雨
     * 2018.07.19
     * @param reinstatementId
     * @return
     */
    @RequestMapping("/selRehabById")
    @ResponseBody
    private ToJson selRehabById(HttpServletRequest request,Integer reinstatementId){
        return hrStaffReinstatementService.selRehabById(request,reinstatementId);
    }

    /**
     * 查看列表,分页
     * 郭心雨
     * 2018.07.19
     * @return
     */
    @RequestMapping("/selAllRehab")
    @ResponseBody
    private ToJson selAllRehab(HttpServletRequest request,Integer page,Integer pageSize,Boolean useFlag,String reinstatementPerson){
        return hrStaffReinstatementService.selAllRehab(request,page,pageSize,useFlag,reinstatementPerson);
    }


    /**
     * 导入
     * 郭心雨
     * 2018.07.23
     * @param request
     * @param response
     * @param file
     * @param session
     * @return
     */
    @ResponseBody
    @RequestMapping("/inputFixAsserts")
    public  ToJson<HrStaffReinstatementWithBLOBs> inputFixAsserts(HttpServletRequest request, HttpServletResponse response, MultipartFile file, HttpSession session){
        return hrStaffReinstatementService.inputFixAsserts(request,response,file,session);
    }



    /**
     * 获取复职类型列表
     * 郭心雨
     * 2018.07.24
     * @param parentNo
     * @return
     */
    @ResponseBody
    @RequestMapping("/fuZhiList")
    public ToJson fuZhiList(String parentNo){
        return hrStaffReinstatementService.fuZhiList(parentNo);
    }

    /**
     * 模糊查询,导出
     * 郭心雨
     * 2018.07.20
     * @param hrStaffReinstatement
     * @param page
     * @param pageSize
     * @param useFlag
     * @return
     */
    @ResponseBody
    @RequestMapping("/selAllRehabBy")
    public ToJson selectList(HttpServletRequest request, HttpServletResponse response, HrStaffReinstatementWithBLOBs hrStaffReinstatement, Integer page, Integer pageSize, boolean useFlag, String export){
        return hrStaffReinstatementService.selectList( request,  response,  hrStaffReinstatement,  page,  pageSize,  useFlag,  export);
    }
}
